package cn.itcast.mr.order;

import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * Author itcast
 * Date 2021/10/17 16:35
 * Desc TODO
 */
public class OrderMapper extends Mapper<LongWritable, Text,OrderBean, NullWritable> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        OrderBean orderBean = new OrderBean();
        if(StringUtils.isNotEmpty(line)){
            String[] orderArr = line.split("\t");
            orderBean.setOid(orderArr[0]);
            orderBean.setPid(orderArr[1]);
            orderBean.setPrice(Double.parseDouble(orderArr[2]));
            context.write(orderBean,NullWritable.get());
        }
    }
}
